package com.xiaoge.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoge.entity.EduNavBar;
import com.xiaoge.exception.BusinessException;
import com.xiaoge.mapper.EduNavBarMapper;
import com.xiaoge.service.EduNavBarService;
import com.xiaoge.vo.EduNavBarVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @Author: 冷俊杰
* @Description: 导航管理
* @DateTime: 2022/11/9 20:01
**/
@Service
public class EduNavBarServiceImpl extends ServiceImpl<EduNavBarMapper, EduNavBar> implements EduNavBarService {

    @Override
    public void InEduNav(EduNavBarVO vo) {
        //导航栏
        String navTitle = vo.getNavTitle();
        //判断导航栏是否被占用
        LambdaQueryWrapper<EduNavBar> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EduNavBar::getNavTitle,navTitle);
        Long i = this.baseMapper.selectCount(wrapper);
        if(i!=0){
            throw new BusinessException("该导航栏已被占用");
        }
        this.baseMapper.InEduNav(vo);
    }

    @Override
    public int UpEduNav(EduNavBarVO vo) {
        return this.UpEduNav(vo);
    }

    @Override
    public Page<EduNavBar> getEduNavBarByPage(Page<EduNavBar> page, String navTitle) {
        List<EduNavBar> eduNavBars = this.baseMapper.ListEduNav(page, navTitle);
        //将刚刚动态sql查询的内容给page对象,让它去实现分页
        page.setRecords(eduNavBars);
        return page;
    }
}
